<template>
    <div>
        <table class="table">
                <tr>
                    <td>商铺名称</td>
                    <td>
                        <input type="text" v-model="data.spmc">
                    </td>
                </tr>
                 <tr>
                    <td>商铺楼层</td>
                    <td>
                        <select v-model="data.splc">
                            <option value="">请选择</option>
                            <option value="一层">一层</option>
                            <option value="二层">二层</option>
                            <option value="三层">三层</option>
                            <option value="四层">四层</option>
                        </select>
                    </td>
                </tr>
                 <tr>
                    <td>联系电话</td>
                    <td>
                        <input type="text" v-model="data.phoe">
                    </td>
                </tr>
                 <tr>
                    <td>商铺编号</td>
                    <td>
                        <input type="text" v-model="data.bh">
                    </td>
                </tr>
                 <tr>
                    <td>状态</td>
                    <td>
                         <select  v-model="data.ztid">
                            <option value="null">请选择</option>
                            <option v-for="m in xlk" :value="m.ztid">{{m.ztmc }}</option>
                            
                        </select>
                    </td>
                </tr>
                    <tr>
                    <td></td>
                    <td>
                      <input type="button" value="修改" @click="xg">

                    </td>
                </tr>
        </table>

    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';
import { useRoute } from 'vue-router';

const stro = useRoute();

const data=ref({
      "id": 1,
      "spmc": "",
      "ztid": 2,
      "splc": "",
      "phoe": "",
      "scsj": "2025-05-13T09:38:33.5946367",
      "sczt": false,
      "bh": "",
      "ztmc": "空置"
})


onMounted(()=>{
    xs();
    xss();
})

const xlk=ref([{
    "ztid": 1,
    "ztmc": "出租中"
}])
const xss=()=>{
    axios.get("https://localhost:7047/api/we/ztxs").then(res=>{
        xlk.value=res.data
    })
}
const xs=()=>{
    var w =stro.query.id
    axios.get("https://localhost:7047/api/we/xq",{params:{id:w}}).then(res=>{
        data.value=res.data
    })
}


const xg=(a:any)=>{

    if(data.value.spmc==""){
        alert("商铺名称不能为空")
        return
    }
      if(data.value.splc==""){
        alert("商铺楼层不能为空")
        return
    }
      if(data.value.phoe==""){
        alert("联系电话不能为空")
        return
    }
      if(data.value.bh==""){
        alert("商铺编号不能为空")
        return
    }
      if(data.value.ztid==null){
        alert("商铺状态不能为空")
        return
    }
    debugger
       if(data.value.phoe.length!=11){
        alert("联系电话格式不正确")
        return
    }


    axios.post("https://localhost:7047/api/we/update",data.value).then(res=>{
        if(res.data>0){
            alert("修改成功")
            location.href="/"
        }else{
            alert("修改失败")
        }
    })
}

</script>

<style scoped>

</style>